Skip to content

fix: types & config fixes#40

Merged
avivkeller merged 1 commit intowebpack:mainfrom
sujalgoel:fix/type-renderer-preserve-generics
Mar 23, 2026
Merged

fix: types & config fixes#40
avivkeller merged 1 commit intowebpack:mainfrom
sujalgoel:fix/type-renderer-preserve-generics

Conversation

@sujalgoel
Copy link
Contributor

Summary

Fixes #30

The custom type resolver in plugins/theme/partials/types.mjs was collapsing TypeScript types too aggressively, producing semantically inaccurate documentation output. This PR restores the correct semantics now that @node-core/doc-kit supports generic types.

Changes

  • reference types now include generic type arguments

    • Before: {Map}, {ReadonlySet}, {Record}
    • After: {Map<string, number>}, {ReadonlySet<string>}, {Record<string, string|string[]|T>}
  • tuple types now render as tuple syntax instead of union syntax

    • Before: {number|number|number}
    • After: {[number, number, number]}
  • conditional types now preserve the full conditional structure

    • Before: {TrueType|FalseType}
    • After: {CheckType extends ExtendsType ? TrueType : FalseType}
  • optional tuple members now render with a trailing ? suffix

  • indexedAccess types now render as T[K] instead of just T

Verification

After regenerating docs with npm run generate-docs, the affected files show correct output:

  • pages/v5.x/webpack/namespaces/esm.md: {Map<string, number>}, {ReadonlySet<string>}, {Iterable<Chunk>}
  • pages/v5.x/webpack/namespaces/sharing.md: {Record<string, string|string[]|T>}
  • pages/v5.x/webpack/namespaces/dependencies.md: {[number, number]} instead of {number|number}

The regenerated pages/v5.x/ output is included in this PR.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 22, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: avivkeller / name: Aviv Keller (3b33ac8)
  • ✅ login: sujalgoel / name: Sujal Goel (3b33ac8)

@sujalgoel sujalgoel force-pushed the fix/type-renderer-preserve-generics branch from 82d256e to db8f98f Compare March 22, 2026 21:06
@avivkeller
Copy link
Member

doc-kit supports generics, but only basic ones at the moment. Most of these are yes to be supported. You'll need to use syntax like Tuple<,,>, etc

Comment on lines +33 to +34
return resolve(type.elementType) + '?';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a type is optional, we should just return the type, there's other ways to say it's optional in doc-kit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, reverted to just returning the type.

Comment on lines +20 to +26
return union(type.elements);
return `[${(type.elements ?? []).map(resolve).join(', ')}]`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuple<...>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to Tuple<>.

Comment on lines +44 to +45
case 'conditional':
return `${resolve(type.trueType)}|${resolve(type.falseType)}`;
return `${resolve(type.checkType)} extends ${resolve(type.extendsType)} ? ${resolve(type.trueType)} : ${resolve(type.falseType)}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support this yet, please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.


case 'indexedAccess':
return resolve(type.elementType ?? type.objectType);
return `${resolve(type.objectType)}[${resolve(type.indexType)}]`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support this yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

@avivkeller
Copy link
Member

Just because generics render a bit strange in the markdown, doesn't mean they'll render strange in doc-kit, please keep the curly brace syntax

@sujalgoel sujalgoel force-pushed the fix/type-renderer-preserve-generics branch 2 times, most recently from d6f52e0 to 36c52b8 Compare March 22, 2026 22:17
@sujalgoel
Copy link
Contributor Author

Updated the tuple case to use Tuple<> format.

@sujalgoel
Copy link
Contributor Author

Reverted to curly brace syntax.

Copy link
Member

@avivkeller avivkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines +33 to +34
return resolve(type.elementType);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return resolve(type.elementType);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, merged with indexedAccess.

case 'reference':
return type.name;

case 'reference': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge this with the above case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, merged intrinsic and reference into one case.


case 'tuple':
return union(type.elements);
return `Tuple<${(type.elements ?? []).map(resolve).join(', ')}>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's make union(type.elements, ', ') work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, updated union to accept a separator param and used union(type.elements, ', ') for tuple.

@avivkeller
Copy link
Member

I'll regenerate the docs to make the check pass when I get a chance

@sujalgoel sujalgoel force-pushed the fix/type-renderer-preserve-generics branch from 36c52b8 to 3c80ad6 Compare March 22, 2026 22:27
@sujalgoel
Copy link
Contributor Author

Thanks!

Co-Authored-By: Aviv Keller <me@aviv.sh>
@avivkeller avivkeller force-pushed the fix/type-renderer-preserve-generics branch from 3c80ad6 to 3b33ac8 Compare March 23, 2026 14:18
@avivkeller avivkeller changed the title fix(types): preserve TypeScript semantics in type renderer fix: types & config fixes Mar 23, 2026
@avivkeller avivkeller merged commit 348f7d0 into webpack:main Mar 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom type renderer is losing TypeScript semantics in generated docs

2 participants